#include <REGX52.H>
/**
 * 灯一开始是常亮状态
 * 按一下变为熄灭状态
 * 两个状态切换
 */

sbit BTN = P3 ^ 7;
sbit LED = P3 ^ 1;

void main()
{
    // 0 常亮，1熄灭
    unsigned char status = 0;
    LED = 1;
    while (1)
    {
        // 按下
        if (BTN == 0)
        {
            while (BTN == 0)
            {
                // 只要还是按下状态，就等待
            }

            // 对2取模，这样值永远是0 1
            status = (status + 1) % 2;

            if (status == 0)
            {
                LED = 1;
            }
            else if (status == 1)
            {
                LED = 0;
            }
        }
    }
}